package com.team7.happycommunity.propertymanagement.service.impl;

import com.team7.happycommunity.propertymanagement.dao.AnnouncementMapper;
import com.team7.happycommunity.propertymanagement.dao.PropertyManageMapper;
import com.team7.happycommunity.propertymanagement.pojo.Announcement;
import com.team7.happycommunity.propertymanagement.pojo.PropertyManage;
import com.team7.happycommunity.propertymanagement.service.AnnoncementService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

import java.util.Date;
import java.util.List;

@Controller
public class AnnoncementServiceImpl implements AnnoncementService {

    @Autowired
    AnnouncementMapper announcementMapper;

    @Autowired
    PropertyManageMapper propertyManageMapper;

    @Override
    public Boolean save(Announcement announcement) {

        announcementMapper.setStatusFalseByAreaId(announcement.getAreaId());
//        if(!re){
//            return false;
//        }
        announcement.setCreateTime(new Date());
        Integer i = announcementMapper.insertSelective(announcement);
        return (i == 0)?false:true;
    }

    @Override
    public List<Announcement> findAnnoncementByPage(Integer currentPage, Integer pageSize,String username) {
        PropertyManage propertyManage = propertyManageMapper.selectByUserName(username);
        return announcementMapper.findAnnoncementByPage(currentPage, pageSize,propertyManage.getVillageId());
    }

    @Override
    public int delete(Integer id) {

        return announcementMapper.deleteByPrimaryKey(id);
    }
}
